<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>

<html>
<head>
<%
%>
<meta charset="UTF-8">
<title>HTML5 채팅 ver 1</title>
<script src="/js/html5/chat/jWebSocket.js" type="text/javascript"></script>
<script type="text/javascript">
	var ws;
	var host=jws.getDefaultServerURL();
	
	window.onload = function() {
		if( window.WebSocket == undefined ) {
			alert("WebSocket을 사용할 수 없습니다");
			return;
		}
		
		try {
			alert(host);
			ws = new WebSocket(host);
			ws.onopen = function(event) {log('접속 완료');  };
			ws.onmessage = function(event) {log('수신:' + event.data);  };
			ws.onclose = function(event) {log('접속 종료');  };
		}
		catch(e) {
			alert(e);
		}
	}
	
	function log(str) {
		var msg = document.getElementById('msg');
		msg.innerHTML = str + "<br />" + msg.innerHTML;
	}
	
	function sendLog() {
		var input_txt = document.getElementById("input_txt");
		ws.send(input_txt.value);
	}
</script>
</head>
<body>

<input type="text" size="14" id="input_txt" />
<input type="button" value="보내기" onclick="sendLog()" />
<div id="msg"></div>


</body>
</html>